package com.hu.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {

    //整合每个微服务的swagger
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        //一个 SwaggerResource对应一个微服务    注意参数： 服务中文名 ， 路径：/zuul前缀/服务的routes访问路径//v2/api-docs  ； 版本
        resources.add(swaggerResource("系统管理", "/hrm/hrm/v2/api-docs", "2.0"));
        resources.add(swaggerResource("课程管理", "/hrm/hrm/v2/api-docs", "2.0"));
        resources.add(swaggerResource("文件上传", "/hrm/fastdfs/v2/api-docs", "2.0"));
        resources.add(swaggerResource("全文搜索", "/hrm/es/v2/api-docs", "2.0"));
        resources.add(swaggerResource("用户管理", "/hrm/user/v2/api-docs", "2.0"));
        return resources;
    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}
